﻿package mortal.game.view.yyZiZuan
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class YYZiZuanModule extends BaseWindow
    {
        private var _rightList:GTileList;
        private var _categorySpr:YYZiZuanCategorySpr;
        private var _monthTitle:GImageBitmap;
        private var _yearTitle:GImageBitmap;
        private var _giftItem:BaseItem;
        private var _giftList:GTileList;
        private var _yyZiZuanBtn:GLoadingButton;
        private var _monthTxt1:GImageBitmap;
        private var _monthTxt2:GImageBitmap;
        private var _yearTxt1:GImageBitmap;
        private var _yearTxt2:GImageBitmap;
        private var _priceTxt:GTextFiled;
        private var _getBtn:GButton;
        private var _style:int = 1;

        public function YYZiZuanModule()
        {
            this.setSize(886, 595);
            this.title = Language.getString(90475);
            return;
        }// end function

        private function setMonthStyle() : void
        {
            this._style = 1;
            this.setRightListDataProvider([ImagesConst.YYZiZuanRight1, ImagesConst.YYZiZuanRight2, ImagesConst.YYZiZuanRight3, ImagesConst.YYZiZuanRight5]);
            this.setGiftShow(GameConst.TYYPurpleMonthGiftCode);
            this.refresh();
            this._monthTitle.visible = true;
            this._yearTitle.visible = false;
            this._monthTxt1.visible = true;
            this._monthTxt2.visible = true;
            this._yearTxt1.visible = false;
            this._yearTxt2.visible = false;
            return;
        }// end function

        private function setYearStyle() : void
        {
            this._style = 2;
            this.setRightListDataProvider([ImagesConst.YYZiZuanRight1, ImagesConst.YYZiZuanRight2, ImagesConst.YYZiZuanRight4, ImagesConst.YYZiZuanRight5]);
            this.setGiftShow(GameConst.TYYPurpleYearGiftCode);
            this.refresh();
            this._monthTitle.visible = false;
            this._yearTitle.visible = true;
            this._monthTxt1.visible = false;
            this._monthTxt2.visible = false;
            this._yearTxt1.visible = true;
            this._yearTxt2.visible = true;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.YYZiZuanTopBg, 4, 35, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.YYZiZuanBottomBg, 4, 161, this));
            this._categorySpr = UICompomentPool.getUICompoment(YYZiZuanCategorySpr);
            this._categorySpr.x = 10;
            this._categorySpr.y = 161;
            this.addChild(this._categorySpr);
            this._rightList = UIFactory.tileList(0, 235, 400, 360, this);
            this._rightList.rowHeight = 84;
            this._rightList.columnWidth = 400;
            this._rightList.horizontalGap = 0;
            this._rightList.verticalGap = 0;
            this._rightList.setStyle("cellRenderer", YYZiZuanRightCellRender);
            this._monthTitle = UIFactory.gImageBitmap(ImagesConst.YYZiZuanTitle1, 200 + 106 + 33, 200 + 141, this);
            this._yearTitle = UIFactory.gImageBitmap(ImagesConst.YYZiZuanTitle2, 200 + 106 + 33, 200 + 141, this);
            this._giftItem = UICompomentPool.getUICompoment(BaseItem);
            this._giftItem.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBg, 4, 4);
            this._giftItem.x = 600 + 29;
            this._giftItem.y = 450 - 6;
            this.addChild(this._giftItem);
            this._giftList = UIFactory.tileList(517 + 140 + 10, 450 + 85, 500, 42, this);
            this._giftList.columnWidth = 50;
            this._giftList.rowHeight = 40;
            this._giftList.setStyle("cellRenderer", YYZiZuanGiftCellRender);
            this._giftList.direction = GBoxDirection.HORIZONTAL;
            this._yyZiZuanBtn = UIFactory.gLoadingButton(ResFileConst.YYZiZuanBtn, 600 + 26, 200 - 139, 118, 44, this);
            this._yyZiZuanBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._monthTxt1 = UIFactory.gImageBitmap(ImagesConst.YYZiZuanLeftTxt1, 100 - 35, 200 + 14, this);
            this._monthTxt2 = UIFactory.gImageBitmap(ImagesConst.YYZiZuanRightTxt1, 100 + 585, 200 + 208, this);
            this._yearTxt1 = UIFactory.gImageBitmap(ImagesConst.YYZiZuanLeftTxt2, 100 - 35, 200 + 14, this);
            this._yearTxt2 = UIFactory.gImageBitmap(ImagesConst.YYZiZuanRightTxt2, 100 + 585, 200 + 208, this);
            this._priceTxt = UIFactory.gTextField("", 630 + 73 - 14, 500 - 52, 220, 20, this, GlobalStyle.textFormatHuang2.center());
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(90476), 600 + 73 + 68 - 18, 500 - 52, 220, 20, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.Yuanbao, 660 + 180 - 14, 500 - 52, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.deleteLine, 645 + 73 + 84 - 14, 500 - 52 + 8, this));
            this._getBtn = UIFactory.gButton(Language.getString(90477), 160 + 580, 401 + 81, 82, 27, this, "RedButton");
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._getBtn.mouseEnabled = false;
            Dispatcher.addEventListener(EventName.YYZiZuanSwicthPanel, this.onSwitchPanel);
            this._categorySpr.switchTag(0);
            this.refresh();
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            if (event.target == this._yyZiZuanBtn)
            {
                Dispatcher.dispatchEvent(new Event(EventName.YYZiZuanAply));
            }
            else if (event.target == this._getBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.YYZiZuanRequestGift, this._style));
            }
            return;
        }// end function

        private function onSwitchPanel(event:DataEvent) : void
        {
            if (int(event.data) == 0)
            {
                this.setMonthStyle();
            }
            else if (int(event.data) == 1)
            {
                this.setYearStyle();
            }
            return;
        }// end function

        private function setRightListDataProvider(param1:Array) : void
        {
            var _loc_2:DataProvider = null;
            var _loc_3:int = 0;
            if (this._rightList)
            {
                _loc_2 = new DataProvider();
                _loc_3 = 0;
                while (_loc_3 < param1.length)
                {
                    
                    _loc_2.addItem({url:param1[_loc_3], index:_loc_3});
                    _loc_3++;
                }
                this._rightList.dataProvider = _loc_2;
                this._rightList.drawNow();
            }
            return;
        }// end function

        private function setGiftShow(param1:int) : void
        {
            var _loc_2:DataProvider = null;
            var _loc_3:ItemGiftBagInfo = null;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:YYZiZuanGiftDataGroup = null;
            if (this._giftItem)
            {
                this._giftItem.itemCode = param1;
                this._giftItem.isBind = true;
            }
            if (this._giftList)
            {
                _loc_2 = new DataProvider();
                _loc_3 = new ItemData(param1).itemInfo as ItemGiftBagInfo;
                _loc_4 = _loc_3.itemList1.split("&");
                _loc_7 = _loc_4.length;
                _loc_8 = 0;
                while (_loc_8 < _loc_4.length)
                {
                    
                    _loc_5 = _loc_4[_loc_8].split("#");
                    _loc_9 = new YYZiZuanGiftDataGroup();
                    _loc_9.itemCode = int(_loc_5[1]);
                    _loc_9.itemAmount = _loc_5[2];
                    _loc_9.isBind = true;
                    _loc_2.addItem(_loc_9);
                    _loc_8++;
                }
                this._priceTxt.text = String(_loc_3.effect);
                this._giftList.dataProvider = _loc_2;
                this._giftList.drawNow();
            }
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_1:* = Cache.instance.YYZiZuan;
            if (_loc_1.yyZiZuanType > 0 && this._style == 1)
            {
                if (!_loc_1.isMonthGet)
                {
                    this.setCanGetStyle();
                }
                else
                {
                    this.setHasGetStyle();
                }
            }
            else if (_loc_1.yyZiZuanType > 1 && this._style == 2)
            {
                if (!_loc_1.isYearGet)
                {
                    this.setCanGetStyle();
                }
                else
                {
                    this.setHasGetStyle();
                }
            }
            else
            {
                this.setCanNotGetStyle();
            }
            this._categorySpr.refresh();
            return;
        }// end function

        private function setCanGetStyle() : void
        {
            this._getBtn.label = Language.getString(90477);
            this._getBtn.mouseEnabled = true;
            this._getBtn.filters = [];
            EffectManager.glowFilterReg(this._getBtn);
            return;
        }// end function

        private function setHasGetStyle() : void
        {
            this._getBtn.mouseEnabled = false;
            this._getBtn.label = Language.getString(90478);
            EffectManager.glowFilterUnReg(this._getBtn);
            this._getBtn.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        private function setCanNotGetStyle() : void
        {
            this._getBtn.mouseEnabled = false;
            this._getBtn.label = Language.getString(90477);
            EffectManager.glowFilterUnReg(this._getBtn);
            this._getBtn.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            Dispatcher.removeEventListener(EventName.YYZiZuanSwicthPanel, this.onSwitchPanel);
            this._rightList.dispose(param1);
            this._rightList = null;
            this._categorySpr.dispose(param1);
            this._categorySpr = null;
            this._monthTitle.dispose(param1);
            this._monthTitle = null;
            this._yearTitle.dispose(param1);
            this._yearTitle = null;
            this._giftItem.dispose(param1);
            this._giftItem = null;
            this._giftList.dispose(param1);
            this._giftList = null;
            this._yyZiZuanBtn.dispose(param1);
            this._yyZiZuanBtn = null;
            this._monthTxt1.dispose(param1);
            this._monthTxt2.dispose(param1);
            this._yearTxt1.dispose(param1);
            this._yearTxt2.dispose(param1);
            this._priceTxt.dispose(param1);
            this._getBtn.dispose(param1);
            this._monthTxt1 = null;
            this._monthTxt2 = null;
            this._yearTxt1 = null;
            this._yearTxt2 = null;
            this._priceTxt = null;
            this._getBtn = null;
            this._style = 1;
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
